#include "timer14.h"

/**
 * Function: TIMER14_Init
 * Description: 配置定时器14(1ms)
 * input param: 无
 * return param: 无
 */
void TIMER14_Init(void)
{
	TMR_TimerBaseInitType TIM_TimeBaseInitStructure;
	NVIC_InitType NVIC_InitStructure;
	RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_TMR14,ENABLE);
	
	TIM_TimeBaseInitStructure.TMR_ClockDivision = TMR_CKD_DIV1;
	TIM_TimeBaseInitStructure.TMR_CounterMode = TMR_CounterDIR_Up;
	TIM_TimeBaseInitStructure.TMR_Period = 1000-1;
	TIM_TimeBaseInitStructure.TMR_DIV = 120-1;
	TIM_TimeBaseInitStructure.TMR_RepetitionCounter = 0;
	TMR_TimeBaseInit(TMR14,&TIM_TimeBaseInitStructure);
	
	TMR_INTConfig(TMR14,TMR_INT_Overflow,ENABLE);
	TMR_Cmd(TMR14,ENABLE);
	
	
	NVIC_InitStructure.NVIC_IRQChannel = TMR14_GLOBAL_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_Init(&NVIC_InitStructure);
}
/**
 * Function: TIM14_IRQHandler
 * Description: 定时器14的中断
 * input param: 无
 * return param: 无
 */
extern uint16_t ColorLight_Time;//设定的灯带颜色切换时间
extern uint8_t Color_Light_Flag;//灯带颜色切换的标志
extern uint8_t flag_10ms;
extern uint8_t flag_40ms;
extern uint8_t flag_1s;
void TMR14_GLOBAL_IRQHandler(void)
{
	static uint16_t count_1ms = 0, count_10ms = 0, count_40ms = 0;
	if(TMR_GetINTStatus(TMR14,TMR_INT_Overflow) == SET)
	{
		TMR_ClearITPendingBit(TMR14,TMR_INT_Overflow);
		//Deal_Time_Set();
		count_1ms++;
		
		if(count_1ms >= 9)
		{
			count_1ms = 0;
			flag_10ms = 1;
			count_10ms ++;
		}
		if(count_10ms >= 4)
		{
			count_10ms = 0;
			flag_40ms = 1;
			count_40ms ++;
		}
		if(count_40ms >= 25)
		{
			count_40ms = 0;
			flag_1s = 1;
		}
		
		
	}
}
